﻿using System.Linq;
using System.Web.Mvc;
using MusicLibrary.Models;

namespace MusicLibrary.Controllers
{
	public class StoreController : Controller
	{
		readonly MusicLibraryEntities _storeDb = new MusicLibraryEntities();

		//
		// GET: /Store/

		public ActionResult Index()
		{
			//var genres = new List<Genre>
			//{
			//	new Genre {Name = "Disco"},
			//	new Genre {Name = "Jazz"},
			//	new Genre {Name = "Rock"}
			//};

			var genres = _storeDb.Genres.ToList();

			return View(genres);
		}

		//
		// GET: /Store/Brose

		public ActionResult Browse (string genre) {
			// Retrieve Genre and its Associated Albums from database
			var genreModel = _storeDb.Genres.Include("Albums")
				.Single(g => g.Name == genre);
			//var genreModel = new Genre {Name = genre};

			return View(genreModel);
		}

		//
		// GET: /Store/Details/5

		public ActionResult Details(int? id)
		{
			var album = _storeDb.Albums.Find(id);
			//var album = new Album { Title = "Album" + id };
			return View(album);
		}

		//
		// GET: /Store/GenreMenu

		//[ChildActionOnly]
		public ActionResult GenreMenu ()
		{
			var genres = _storeDb.Genres.ToList();
			return PartialView(genres);
		}
	}
}
